package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.vo.CheckGroupVO;
import com.itheima.health.vo.SetmealVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface SetmealMapper extends BaseMapper<Setmeal> {

    //套餐中间表插入
    @Insert("insert into t_setmeal_checkgroup values (#{gid},#{checkgroupId})")
    void addSetmealAndChenkGroupInfo(@Param("gid")Integer gid, @Param("checkgroupId")Integer checkgroupId);

    //根据套餐id 查询套餐
    @Select("select name,age,remark,img,sex from t_setmeal where id = #{id}")
    SetmealVO findSetmealById(@Param("id") int id);

    //根据套餐id 查询检查项
    @Select("select tc.id,tc.name,tc.remark from t_setmeal_checkgroup tsc,t_checkgroup tc where tc.id=tsc.CHECKGROUP_ID and tsc.SETMEAL_ID=#{id}")
    List<CheckGroupVO> findCheckGroupInfoBySetmealId(@Param("id") int id);


    //根据检查项id 查询 检查项信息
    @Select("SELECT tc.name FROM t_checkgroup_checkitem tcc ,t_checkitem tc WHERE tcc.CHECKITEM_ID = tc.ID AND tcc.CHECKGROUP_ID = #{id}")
    List<CheckItem> findCheckitemIdsByCheckGroupId(@Param("id") Integer id);

}
